import { AuthService } from '@service/auth.service';
import { BaseService } from '@service/base.service';
import { AbsFormUtil } from '@abstract/form';
import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { FormBuilder } from '@angular/forms';
import { IBaseNotice } from '@model/base';
@Component({
  selector: 'app-base-notice',
  templateUrl: './base-notice.component.html',
  styleUrls: ['./base-notice.component.less']
})
export class BaseNoticeComponent extends AbsFormUtil implements OnInit {

	nzLoading = false;
	data = [];

	
	constructor(
		private baseService: BaseService,
		private nzMessageService: NzMessageService,
		private fb: FormBuilder,
		private authService: AuthService
	) {
		super();
		this.authList = this.authService.getAuth();

	}

	ngOnInit() {
		this.buildForm();
		this.onSearch();
	}
	buildForm() {
		this.validateForm = this.fb.group({
			status : [''],
			type : ['']
		});
	}

	async onSearch(isPageInit?: boolean) {
		this.nzLoading = true;
		if (isPageInit) {
			this.page.page = 1;
		}
		const params = { ...this.validateForm.value, ...this.page };
		const result = await this.baseService.getNoticeList(params);
		this.data = result.data.list;
		this.page.total = result.data.totalCount;
		this.nzLoading = false;

	}



	async del(item: IBaseNotice) {
		await this.baseService.deleteNotice(item.id);
		this.nzMessageService.success('删除成功');
		this.onSearch();
	}

	async update(item: IBaseNotice) {
		await this.baseService.updateNotice(item.id);
		this.nzMessageService.success('已读成功');
		this.onSearch();
	}


}
